﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TaoBaoShuaDan20140530
{
    public partial class taobao : Form
    {
        public taobao()
        {
            InitializeComponent();
        }

        private void btBrowse_Click(object sender, EventArgs e)
        {
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                tbFilePath.Text = openFileDialog.FileName;
                //var sr = new StreamReader(openFileDialog.FileName);
                //MessageBox.Show(sr.ReadToEnd());
                //sr.Close();
            }
        }

        private void btOpen_Click(object sender, EventArgs e)
        {
            if (!IsExistPathFile(tbFilePath.Text))
            {
                MessageBox.Show("输入文件路径有误");
                return;
            }

            var webSiteList = new List<DataElement>();
            var fs = new FileStream(tbFilePath.Text, FileMode.Open);
            var sr = new StreamReader(fs, Encoding.Default);
            while (!sr.EndOfStream)
            {
                var element = new DataElement(sr.ReadLine(),false);
                webSiteList.Add(element);
            }
            sr.Close();
            fs.Close();

            dGWData.DataSource = webSiteList;
        }

        private bool IsExistPathFile(string text)
        {
            if (text == "")
            {
                return false;
            }
            return true;
        }
    }
}
